package com.unibuy.smartdevice.tools;

import com.unibuy.smartdevice.SchedulerAbstract;
import com.unibuy.smartdevice.exception.ErrorCode;

import java.io.IOException;

public abstract class HandlerMainAdpter extends SchedulerAbstract {
    private HandlerMain handlerMain;
    private HandlerMain srcHandlerMain;

    public HandlerMainAdpter(HandlerMain srcHandlerMain) {
        this.srcHandlerMain = srcHandlerMain;
        this.handlerMain = setHandlerMain();
    }

    @Override
    protected void execute() {
        try {
            execute(handlerMain);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

//    @Override
//    protected void exception(ErrorCode errorCode, String message) {
//        exception(errorCode, message, handlerMain);
//    }

    public HandlerMain getSrcHandlerMain() {
        return srcHandlerMain;
    }

    public HandlerMain getHandlerMain() {
        return handlerMain;
    }

    protected abstract HandlerMain setHandlerMain();
    protected abstract void execute(HandlerMain handlerMain) throws IOException;
    protected abstract void close(HandlerMain handlerMain);
//    protected void exception(ErrorCode errorCode, String message, HandlerMain handlerMain) {
//        handlerMain.error(getClass().getSimpleName(), errorCode, message);
//    }

    @Override
    protected String description() {
        return setCls().getSimpleName();
    }
}
